package com.tangding.hprose.api.server.command.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.google.common.base.Strings;
import com.tangding.common.exception.GException;
import com.tangding.common.tools.ErrorConstants;
import com.tangding.hprose.api.client.HproseAsClient;
import com.tangding.hprose.api.server.command.Command;
import com.tangding.hprose.api.server.command.Response;
import com.tangding.hprose.api.server.command.impl.testForData.TestAddAccount;
import com.tangding.hprose.api.server.command.impl.testForData.TestAddNeon;
import com.tangding.hprose.api.server.command.impl.testForData.TestAddNotice;
import com.tangding.hprose.api.server.command.impl.testForData.TestBigRewardControl;
import com.tangding.hprose.api.server.command.impl.testForData.TestCancelBigReward;
import com.tangding.hprose.api.server.command.impl.testForData.TestCommand;
import com.tangding.hprose.api.server.command.impl.testForData.TestControlPlayer;
import com.tangding.hprose.api.server.command.impl.testForData.TestDelNeon;
import com.tangding.hprose.api.server.command.impl.testForData.TestDelNotice;
import com.tangding.hprose.api.server.command.impl.testForData.TestForceOutline;
import com.tangding.hprose.api.server.command.impl.testForData.TestInsertControl;
import com.tangding.hprose.api.server.command.impl.testForData.TestQueryGameSettings;
import com.tangding.hprose.api.server.command.impl.testForData.TestQueryGamesSettings;
import com.tangding.hprose.api.server.command.impl.testForData.TestQueryOneAccount;
import com.tangding.hprose.api.server.command.impl.testForData.TestQueryTableUsers;
import com.tangding.hprose.api.server.command.impl.testForData.TestQueryUserDetails;
import com.tangding.hprose.api.server.command.impl.testForData.TestQueryUsers;
import com.tangding.hprose.api.server.command.impl.testForData.TestReleaseAGun;
import com.tangding.hprose.api.server.command.impl.testForData.TestSummary;
import com.tangding.hprose.api.server.command.impl.testForData.TestSysMsgs;
import com.tangding.hprose.api.server.command.impl.testForData.TestTables;
import com.tangding.hprose.api.server.command.impl.testForData.TestUpdateGamesSettings;
import com.tangding.hprose.api.server.command.impl.testForData.TestWatchingTable;
import com.tangding.hprose.api.server.command.impl.testForData.TestZHXControl;

/**
 * @description 
 *
 * @author Ranger
 * @version 2017年11月21日_下午4:43:00
 *
 */
@Component
public class HproseRedirect implements Command {

	static Map<String, TestCommand> testCommands = new HashMap<>();
	static {
		testCommands.put("QueryUsers", new TestQueryUsers());
		testCommands.put("QueryTableUsers", new TestQueryTableUsers());
		testCommands.put("ControlPlayer", new TestControlPlayer());
		testCommands.put("Tables", new TestTables());
		testCommands.put("QueryGameSettings", new TestQueryGameSettings());
		testCommands.put("QueryGamesSettings", new TestQueryGamesSettings());
		testCommands.put("UpdateGamesSettings", new TestUpdateGamesSettings());
		testCommands.put("QueryOneAccount", new TestQueryOneAccount());
		testCommands.put("ReleaseAGun", new TestReleaseAGun());
		testCommands.put("Summary", new TestSummary());
		testCommands.put("SysMsgs", new TestSysMsgs());
		testCommands.put("AddNeon", new TestAddNeon());
		testCommands.put("AddNotice", new TestAddNotice());
		testCommands.put("DelNotice", new TestDelNotice());
		testCommands.put("DelNeon", new TestDelNeon());
		testCommands.put("ForceOutline", new TestForceOutline());
		testCommands.put("AddAccount", new TestAddAccount());
		
		testCommands.put("InsertControl", new TestInsertControl());
		testCommands.put("ZHXControl", new TestZHXControl());
		testCommands.put("BigRewardControl", new TestBigRewardControl());
		testCommands.put("CancelBigReward", new TestCancelBigReward());
		testCommands.put("WatchingTable", new TestWatchingTable());
		
		testCommands.put("QueryUserDetails", new TestQueryUserDetails());
	}
	
	@Override
	public Response exe(Object... params) throws GException {
		if (params == null || params.length == 0) {
			throw new GException(ErrorConstants.ERR_ILLEGAL_REQUEST);
		}
		
		String cmd = (String)(params[0]);
		if (Strings.isNullOrEmpty(cmd)) {
			throw new GException(ErrorConstants.ERR_ILLEGAL_REQUEST);
		}
		
		Object result = null;
		
		/*if (testCommands.containsKey(cmd)) {
			result = testCommands.get(cmd).products();//测试代码
		}else {
			throw new GException(ErrorConstants.ERR_NOT_SIMULATION);
		}*/
		if (params.length == 1) {
			result = HproseAsClient.invoke(cmd);
		}else {
			Object[] data = new Object[params.length - 2];
			System.arraycopy(params, 1, data, 0, data.length);
			result = HproseAsClient.invoke(cmd, data);
		}
		return doResponseSucc(result);
	}
}
